﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Trirand.Web.Mvc;

namespace Catalyst.Mvc
{
	public partial class LiteGrid<TGrid>
	{
		public void FormatColumn(JQGridColumnFormatter formatter, params string[] dataFields)
		{
			dataFields.ToList().ForEach(d => Columns.Find(c => c.DataField == d).Formatter = formatter);
		}

		public void AddClientSideValidator(JQGridEditClientSideValidator validator, params string[] dataFields)
		{
			foreach (string dataField in dataFields)
			{
				JQGridColumn column = Columns.Find(c => c.DataField == dataField);
				column.EditClientSideValidators.Add(validator);

				if (validator is RequiredValidator)
				{
					column.EditDialogFieldSuffix = " *";
				}
			}
		}

		public void GroupSummary(string dataField, GroupSummaryType groupSummaryType, string groupTemplate)
		{
			JQGridColumn column = Columns.Find(c => c.DataField == dataField);
			column.GroupSummaryType = groupSummaryType;
			column.GroupTemplate = groupTemplate;
		}

		public void AddFooterValue(string dataField, string value)
		{
			JQGridColumn column = Columns.Find(c => c.DataField == dataField);
			column.FooterValue = value;
		}
	}
}
